/*
 * @Descripttion:
 * @version:
 * @Author: spring
 * @Date: 2022-04-16 22:58:51
 * @LastEditors: spring
 * @LastEditTime: 2022-04-18 16:36:00
 */
import { createContext, memo, useReducer } from "react";
import Count from "./count";
import Person from "./person";
import store from "../../useReducerStore";
interface context {
  appState: Object;
  dispatch: Function;
}
const { multipleState } = store;

export const AppContext = createContext<context>({
  appState: multipleState,
  dispatch: (data: any) => data,
});

export default memo(function App() {
  const { reducer, multipleState } = store;
  const [appState, appDispatch] = useReducer(
    reducer,
    multipleState,
    (states) => states
  );

  return (
    <AppContext.Provider value={{ appState, dispatch: appDispatch }}>
      <Count />
      <Person />
    </AppContext.Provider>
  );
})
